<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>

</head>
<jsp:include page="../default.jsp" />
<body>
	<div style="padding-bottom: 5px; padding-top: 5px;">
		<fieldset id="query">
			<legend>
				<span style="font-weight: bold;">查询条件</span>
			</legend>
			<div id="form" class="fieldset-body">
				<table width="100%" cellspacing="0" cellpadding="0" border="0">
					<tr height="34px">
						<td align="right"><span>代码：</span></td>
						<td><input name="code" class="mini-textbox"
							vtype="maxLength:20;" /></td>
						<td align="right"><span>名称：</span></td>
						<td><input name="name" class="mini-textbox"
							vtype="maxLength:25;" /></td>
						<td align="right"></td>
						<td></td>
					</tr>
					<tr height="34px">
						<td align="right"><span></span></td>
						<td></td>
						<td align="right"><span></span></td>
						<td></td>
						<td align="right"></td>
						<td align="left"><a class="mini-button" value="查询"
							iconCls="icon-search" onclick="query()">查询</a>&nbsp;&nbsp;<a
							class="mini-button" value="重置" iconCls="icon-reload"
							onclick="CommonUtil.prototype.reset()">重置</a></td>
					</tr>
				</table>
			</div>
		</fieldset>
	</div>
	<div class="mini-toolbar" style="border-bottom: 0;">
		<a class="mini-button" iconCls="icon-add" onclick="toForm('add')">新增</a>
		<a class="mini-button" iconCls="icon-edit" onclick="toForm('edit')">修改</a>
		<a class="mini-button" iconCls="icon-node" onclick="toForm('view')">查看</a>
		<a class="mini-button" iconCls="icon-remove" onclick="toRemove()">删除</a>
		<a class="mini-button" iconCls="icon-node" onclick="toRoleAuth()">权限配置</a>
		<a class="mini-button" iconCls="icon-node" onclick="toRoleUser()">角色授权</a>
	</div>
	<div class="mini-fit">
		<div id="datagrid" class="mini-datagrid"
			style="width: 100%; height: 100%;"
			url="${pageContext.request.contextPath}/auth/role/query.do"
			idField="id" multiSelect="true" allowUnselect="true"
			allowAlternating="true" onload="PageHelper.prototype.commonError">
			<div property="columns">
				<div type="checkcolumn"></div>
				<div field="code" headerAlign="center">代码</div>
				<div field="name" headerAlign="center">名称</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">   
    	new PageHelper().init();
    	mini.parse();
    	var grid = mini.get("datagrid");
		grid.load();
		var form = new mini.Form("#form");
		
		$(function(){
			var action = '${action}';
			if(action != 'roleUser'){
				$(".mini-toolbar .mini-button:eq(5)").hide();
			}else{
				$(".mini-toolbar .mini-button:eq(5)").siblings().hide();
			}
		})
		   
    	function query(){
    		if (form.isValid() == false) return;
			grid.load(form.getData(true));
    	}
    	
    	function toForm(action){
    		if(action == "edit" || action == "view"){
    			var row = CommonUtil.prototype.getSelectRow();
    			if(!row){
    				return;
    			}	
    		}   		
    		mini.open({
    			url: "${pageContext.request.contextPath}/auth/role/toForm.do",
    			title: "角色信息", 
    			width: 600, 
    			height: 400,
    			allowResize : false,
   				onload: function () {
        			var iframe = this.getIFrameEl();
        			var data = {action: action};
        			if(row){
        				data["id"] = row.id;
        			}
        			iframe.contentWindow.setData(data);
    			},
    			ondestroy: function (action) {
        			grid.reload();
        			grid.clearSelect();
    			}
			});
    	}
    	
    	function toRemove(){
    		var keys = CommonUtil.prototype.getSelectKeys(null, "id");
    		if(keys){
    			mini.confirm("确认删除", "提醒", function(action) {
    				if(action == "ok"){
        				CommonUtil.prototype.mask();
        				$.ajax({
                        	url: "${pageContext.request.contextPath}/auth/role/remove.do",
                        	data : {keys: keys},
                        	type : "POST",
    						dataType : "json",
                        	success: function (data, textStatus, jqXHR) {
                        		CommonUtil.prototype.unmask();
                        		if(data.success){
                        			mini.alert("删除成功", "提醒", function(){
    									grid.reload();
            							grid.clearSelect();
    								});
                        		}                       
                        	}
                    	});
    				}
    			});
    		}
    	}
    	
    	function toRoleUser(){
    		var row = CommonUtil.prototype.getSelectRow();
			if(!row){
				return;
			}
			mini.open({
    			url: "${pageContext.request.contextPath}/auth/userRole/toRoleUser.do",
    			title: "角色授权", 
    			width: 600, 
    			height: 400,
    			allowResize : false,
   				onload: function () {
        			var iframe = this.getIFrameEl();
        			var data = {};
        			if(row){
        				data["id"] = row.id;
        			}
        			iframe.contentWindow.setData(data);
    			},
    			ondestroy: function (action) {
        			grid.reload();
        			grid.clearSelect();
    			}
			});
    	}
    	
    	function toRoleAuth(){
    		var row = CommonUtil.prototype.getSelectRow();
			if(!row){
				return;
			}
			mini.open({
    			url: "${pageContext.request.contextPath}/auth/roleAuth/toRoleAuth.do",
    			title: "权限配置", 
    			width: 600, 
    			height: 400,
    			allowResize : false,
   				onload: function () {
        			var iframe = this.getIFrameEl();
        			var data = {};
        			if(row){
        				data["id"] = row.id;
        			}
        			iframe.contentWindow.setData(data);
    			},
    			ondestroy: function (action) {
        			grid.reload();
        			grid.clearSelect();
    			}
			});
    	}
	</script>
</body>
</html>
